<?php
ini_set('display_errors', '0');     # don't show any errors...
error_reporting(E_ALL | E_STRICT);  # ...but do log them
require_once 'jq-config.php';
// include the jqGrid Class
require_once ABSPATH."php/jqGrid.php";
// include the driver class
require_once ABSPATH."php/jqGridPdo.php";
// Connection to the server
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
// Tell the db that we use utf-8
jqGridDB::query($conn,"SET NAMES utf8");

// Create the jqGrid instance
$grid = new jqGridRender($conn);
//Activate debug mode
//$grid->debug = true;
// Write the SQL Query
$grid->SelectCommand = 'SELECT * FROM twitts';
// Set output format to json
$grid->dataType = 'json';
// Let the grid create the model
$grid->setColModel();

// point to Fright column to use the function named MyFormatter
$grid->setColProperty('polarity', array('formatter'=>'js:MyFormatter'));


// Writh the MyFormatter function

$myformat = <<<FORMATFREIGHT
function MyFormatter (cellValue, options, rowdata)
{
    var color = (parseFloat(cellValue) > 0) ? " style='background-color:green;" : " style='background-color:red;";
    color = color + "width:100%;height:100%'";
    var cellHtml = "<div" + color +"></div>";
    return cellHtml;
}
FORMATFREIGHT;

// Output the function with setJSCode
$grid->setJSCode($myformat);

// Set the url from where we obtain the data
$grid->setUrl('jqGrid/grid.php');
// Set some grid options
$grid->setGridOptions(array(
    "rowNum"=>10,
    "height"=>250,
    "rowList"=>array(10,20,30),
    "sortname"=>"id",
    "width" => "100%",
    "height" =>"100%",
    "hoverrows" => true
));
// Set the url from where we get the data
$grid->setSubGridGrid('jqGrid/details.php');
// Enjoy
$grid->renderGrid('#grid','#pager',true, null, null, true,true);
$conn = null;
?>
